<template>
  <!-- 商家信息组件 -->
  <div class="shop-info">
    <div class="shop-top">
      <img :src="shop.logo" alt="" />
      <span class="title">{{ shop.name }}</span>
    </div>
    <div class="shop-middle">
      <!-- 左半部分盒子 -->
      <div class="shop-middle-item shop-middle-left">
        <!-- 总销量盒子 -->
        <div class="info-sells">
          <div class="sells-count">
            {{ shop.sells | sellCountFilter }}
          </div>
          <div class="sells-text">总销量</div>
        </div>
        <!-- 全部宝贝盒子 -->
        <div class="shop-goods-info">
          <div class="all-goods-count">
            {{ shop.goodsCount}}
          </div>
          <div class="goods-text">全部宝贝</div>
        </div>
      </div>
      <!-- 右半部分盒子 -->
      <div class="shop-middle-item shop-middle-right">
        <table>
          <tr v-for="(item, index) in shop.score" :key="index">
            <td>{{ item.name }}</td>
            <td class="score" :class="{ 'score-better': item.isBetter }">
              {{ item.score }}
            </td>
            <td class="better" :class="{ 'gao': item.isBetter }">
              <!-- 秒啊 -->
              <span>{{ item.isBetter ? "高" : "低" }}</span>
            </td>
          </tr>
        </table>
      </div>
    </div>
    <div class="shop-bottom">
      <div class="enter-shop"><a href="http://www.4399.com">进来玩呀</a></div>
    </div>
  </div>
</template>

<script>
export default {
  props: {
    shop: {
      type: Object,
      //  default(){
      //    return {}
      //  }
      defalut: () => ({})
    }
  },
  // 可以查看props里面的属性
  watch: {
    shop(value) {
      console.log(value);
    }
  },
  filters: {
    sellCountFilter: function(value) {
    if(value<10000) return value;
    // tofixed保留小数点后n位小数
    return (value/10000).toFixed(2)+'万'  
    }
  }
};
</script>

<style>
.shop-info {
  padding: 25px 8px;
  border-bottom: 5px solid #f2f5f8;
}
.shop-top {
  line-height: 45px;
  display: flex;
  align-items: center;
}
.shop-top img {
  width: 45px;
  height: 45px;
  border-radius: 50%;
  border: 1px solid rgba(0, 0, 0, 0.1);
}
.shop-top .title {
  margin-left: 10px;
  /* 垂直对齐方式 */
  vertical-align: center;
}
.shop-middle {
  margin-top: 15px;
  display: flex;
  /* 纵轴的中心点对齐 */
  align-items: center;
}
.shop-middle-item {
  flex: 1;
}
.shop-middle-left {
  display: flex;
  /* 横轴上的对齐方式 */
  /* http://www.chenzhicheng.com/space-around-vs-space-evenly/ */
  justify-content: space-evenly;
  text-align: center;
  border-right: 1px solid rgba(0, 0, 0, 0.1);
}
.sells-count,
.all-goods-count {
  font-size: 18px;
}

.sells-text,
.goods-text {
  margin-top: 8px;
  font-size: 12px;
}

.shop-middle-right {
  font-size: 13px;
  color: #333;
}

.shop-middle-right table {
  width: 120px;
  margin-left: 30px;
}
table td {
  padding: 3px 0;
}
.score {
  color: #5ea732;
}

.score-better {
  color: #f13e3a;
}
.better{
    background-color: #5ea732;
    color: #fff;
    text-align: center;
}

.gao{
  background-color: #f13e3a;
}
.shop-bottom{
  text-align: center;
  margin-top: 15px;
}
.enter-shop{
  line-height: 30px;
  text-align: center;
  width: 150px;
  height: 30px;
  display: inline-block;
  background-color: #f3f5f8;
  border-radius: 10px;
}
</style>
